package com.xm.xmapp.fragment;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.xm.xmapp.R;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.base.BaseFragment;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.request.bean.Reset_user_passwordRequest;
import com.xm.xmapp.tools.Des4;
import com.xm.xmapp.tools.StringTools;
import com.xm.xmapp.tools.Tools;

public class ForGetPasswordFragment2 extends BaseFragment implements OnClickListener {

	private String phone, yanzhengma;
	private EditText password1, password2;
	private TextView next;

	public ForGetPasswordFragment2() {

	}

	public String getYanzhengma() {
		return yanzhengma;
	}

	public void setYanzhengma(String yanzhengma) {
		this.yanzhengma = yanzhengma;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Override
	public int setContentView() {
		return R.layout.fragment_forgetpassword2;
	}

	@Override
	public void initView() {

		password1 = (EditText) findViewById(R.id.password1);
		password2 = (EditText) findViewById(R.id.password2);
		next = (TextView) findViewById(R.id.next);
	}

	@Override
	public void initData() {

	}

	@Override
	public void initEvent() {

		next.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.next:
			if (!StringTools.isLength(password1.getText().toString(), 6)) {
				Tools.showMessage("密码至少为6位");
			} else if (!password1.getText().toString().equals(password2.getText().toString())) {
				Tools.showMessage("两次输入密码不同");

			} else {
				Reset_user_passwordRequest requestBean = new Reset_user_passwordRequest();
				requestBean.phone = phone;
				requestBean.code = yanzhengma;
				requestBean.password = Des4.encode(password1.getText().toString());
				promptDialog.show();
				MyAppcation.getMyAppcation().getPostData(getActivity(), requestBean, new GetDataInterFace<String>() {

					@Override
					public void onResponse(String response) {
						getActivity().finish();
						promptDialog.dismiss();
					}
				}, new DisssmissInterFace() {

					@Override
					public void putError(VolleyError error) {
						promptDialog.dismiss();
					}
				});
			}

			break;

		default:
			break;
		}
	}

}
